/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package documenteditor.entidade.model;

import java.io.Serializable;
import java.util.Date;
import javax.persistence.AssociationOverride;
import javax.persistence.AssociationOverrides;
import javax.persistence.Column;
import javax.persistence.EmbeddedId;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import org.hibernate.annotations.ForeignKey;

/**
 *
 * @author gleidson.moura
 */
@Entity
@Table(name = "SERVICO_VENDA")
@AssociationOverrides({ @AssociationOverride(name = "id.servico", joinColumns = @JoinColumn(name = "idServico")),
                        @AssociationOverride(name = "id.venda", joinColumns = @JoinColumn(name = "idVenda")) })

public class ServicoVenda implements Serializable {
    private static final long serialVersionUID = 1L;
    @EmbeddedId
    private ServicoVendaPK idServicoVenda;

    @Column(name="DESCRICAO_SERVICO", nullable=true)
    private String descricaoServico;

    @Column(name="HORA_INICO", nullable=true)
    @Temporal(TemporalType.TIMESTAMP)
    private Date horaInicio;

    @Column(name="HORA_TERMINO", nullable=true)
    @Temporal(TemporalType.TIMESTAMP)
    private Date horaTermino;

    @Column(name="VALOR_SERVICO", scale=2, nullable=false)
    private Long valorServico;

    @ManyToOne(targetEntity=Usuario.class, fetch=FetchType.LAZY)
    @JoinColumn(name="ID_USUARIO", nullable=false)
    @ForeignKey(name="FK_SERVICO_VENDA_USUARIO")
    private Usuario usuario;

    @ManyToOne(targetEntity=Cliente.class, fetch=FetchType.LAZY)
    @JoinColumn(name="ID_CLIENTE", nullable=false)
    @ForeignKey(name="FK_SERVICO_VENDA_CLIENTE")
    private Cliente cliente;

    public ServicoVendaPK getId() {
        return idServicoVenda;
    }

    public void setId(ServicoVendaPK id) {
        this.idServicoVenda = id;
    }

    public Cliente getCliente() {
        return cliente;
    }

    public void setCliente(Cliente cliente) {
        this.cliente = cliente;
    }

    public String getDescricaoServico() {
        return descricaoServico;
    }

    public void setDescricaoServico(String descricaoServico) {
        this.descricaoServico = descricaoServico;
    }

    public Date getHoraInicio() {
        return horaInicio;
    }

    public void setHoraInicio(Date horaInicio) {
        this.horaInicio = horaInicio;
    }

    public Date getHoraTermino() {
        return horaTermino;
    }

    public void setHoraTermino(Date horaTermino) {
        this.horaTermino = horaTermino;
    }

    public ServicoVendaPK getIdServicoVenda() {
        return idServicoVenda;
    }

    public void setIdServicoVenda(ServicoVendaPK idServicoVenda) {
        this.idServicoVenda = idServicoVenda;
    }

    public Usuario getUsuario() {
        return usuario;
    }

    public void setUsuario(Usuario usuario) {
        this.usuario = usuario;
    }

    public Long getValorServico() {
        return valorServico;
    }

    public void setValorServico(Long valorServico) {
        this.valorServico = valorServico;
    }
    
    @Override
    public int hashCode() {
        int hash = 0;
        hash += (idServicoVenda != null ? idServicoVenda.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof ServicoVenda)) {
            return false;
        }
        ServicoVenda other = (ServicoVenda) object;
        if ((this.idServicoVenda == null && other.idServicoVenda != null) || (this.idServicoVenda != null && !this.idServicoVenda.equals(other.idServicoVenda))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "documenteditor.entidade.model.ServicoVenda[id=" + idServicoVenda + "]";
    }

}
